<%@ include file="/common/taglibs.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Spring3-MiniWeb | addUser</title>

<!-- CSS  -->
<link href="<c:url value="/resources/blueprint/screen.css" />"
	rel="stylesheet" type="text/css" />

<link href="<c:url value="/resources/style.css" />" rel="stylesheet"
	type="text/css" />


<!-- JS Library -->
<script type="text/javascript"
	src="<c:url value="/resources/jquery/1.5/jquery.js" />"></script>

<script type="text/javascript"
	src="<c:url value="/resources/validate/jquery.validate.js" />"></script>

<script type="text/javascript"
	src="<c:url value="/resources/validate/messages_cn.js" />"></script>


</head>
<body>

	<c:url var="saveUrl" value="/account/user/save" />

	<div class="container">
		<%@ include file="/common/header.jsp"%>
		<div id="content">
			<div class="span-24 last">

				<form:form id="addUserForm" modelAttribute="userAttribute"
					method="post" action="${saveUrl}">

					<input type="hidden" id="oldLoginName"
						value="${userAttribute.loginName }">

					<table>

						<tr>
							<td><form:label path="loginName">登录名:</form:label></td>
							<td><form:input path="loginName" size="40" /></td>
						</tr>

						<tr>
							<td><form:label path="name">用户名:</form:label></td>
							<td><form:input path="name" size="40" /></td>
						</tr>

						<tr>
							<td><form:label path="password">密码:</form:label></td>
							<td><form:password path="password" showPassword="true"
									size="40" /></td>
						</tr>

						<tr>
							<td><label>确认密码:</label>
							</td>
							<td><input type="password" id="passwordConfirm"
								name="passwordConfirm" size="40" value="${password}" />
							</td>
						</tr>


						<tr>
							<td><form:label path="email">邮箱:</form:label></td>
							<td><form:input path="email" size="40" /></td>
						</tr>

					</table>

					<fieldset>
						<legend>角色</legend>

						<c:forEach var="roleList" items="${roleList }">
							<form:checkbox path="roleCheckBox[${roleList.id }]"
								value="${roleList.id}" label="${roleList.name }" />
						</c:forEach>
					</fieldset>

					<input type="submit" value="Save" />
					<input type="button" value="back" onclick="history.back()" />
				</form:form>
			</div>
		</div>
		<%@ include file="/common/footer.jsp"%>
	</div>
</body>
<script type="text/javascript">
	$(document).ready(function() {
		//聚焦第一个输入框
		$("#loginName").focus();

		//为inputForm注册validate函数
		$("#addUserForm").validate({
			rules : {
				loginName : {
					required : true,
					remote : {
						type : "get",
						url : "/spring3-miniweb/account/user/checkLoginName",
						datatype : "json",
						data : {
							loginName : function() {
								return $("#loginName").val();
							},
							oldLoginName : function() {
								return $("#oldLoginName").val();
							}
						}
					}
				},
				name : "required",
				password : {
					required : true,
					minlength : 3
				},
				passwordConfirm : {
					equalTo : "#password"
				},
				email : "email",
				roleCheckBox : "required"
			},
			messages : {
				loginName : {
					remote : "用户登录名已存在"
				},
				passwordConfirm : {
					equalTo : "输入与上面相同的密码"
				}
			}
		});
	});
</script>
</html>